package cn.edu.scnu.service;

import cn.edu.scnu.entity.Movie;
import cn.edu.scnu.mapper.MovieMapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class MovieService extends ServiceImpl<MovieMapper, Movie> {
    @Autowired
    private MovieMapper movieMapper;
    @Autowired
    private RedisTemplate redisTemplate;

    public Map<String, Object> queryP(Integer pageNo, Integer pageSize) {
        QueryWrapper<Movie> queryWrapper=new QueryWrapper<>();
        int count=movieMapper.selectCount(queryWrapper).intValue();
        Page<Movie> page= new Page<>(pageNo, pageSize);
        Page<Movie> moviePage=movieMapper.selectPage(page, queryWrapper);
        Map<String, Object> map = new HashMap<>();
        map.put("count", count);
        map.put("records", moviePage.getRecords());
        return map;
    }
}
